/***********************************************************************
 * Module:  MonitoringPointController.java
 * Author:  Administrator
 * Purpose: Defines the Class MonitoringPointController
 ***********************************************************************/

package ishitong.configManagement.controller;

import ishitong.vehicleManagement.model.MonitoringPoint;
import ishitong.commons.pagination.Pagination;
import ishitong.common.SysCodeType;
import ishitong.common.model.SysCode;
import ishitong.vehicle.common.model.Certification;
import ishitong.vehicle.common.model.Lane;
import ishitong.vehicle.common.model.Section;
import ishitong.vehicle.common.service.biz.CertificationService;
import ishitong.vehicle.common.service.biz.LaneService;
import ishitong.vehicleManagement.service.biz.impl.SPIMonitoringPointService;
import ishitong.vehicleManagement.service.biz.impl.SPIRoadSectionService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.ishitong.platform.common.page.Page;

/** @pdOid 7f20489f-8b0e-4476-a09b-3eb6b530c79d */
@Controller
public class MonitoringPointController extends ishitong.common.controller.ActionController {
   /** @pdOid ab9154e2-eb50-4bc0-be57-02152cd73a7b */
   private static final String MP_SCH = "/configManagement/monitoringPoint/monitoringPointSearch";
   /** @pdOid fdecf803-3dc6-4da8-8c4c-75bf4d029ff6 */
   private static final String MP_SCH_LST = "/configManagement/monitoringPoint/monitoringPointSearchList";
   /** @pdOid 871d62f4-9f6a-4841-89c2-b8f68a4c8c27 */
   private static final String MP_EDT = "/configManagement/monitoringPoint/monitoringPointEdit";
   /** @pdOid 66913495-b68b-42d0-b017-975dbb213d54 */
   private static final String MP_VIW = "/configManagement/monitoringPoint/monitoringPointView";
   /** @pdOid 786b3461-3fc5-4c5a-aef9-09c59f0592ce */
   private static final String LAN_LST = "/configManagement/monitoringPoint/monitoringLaneList";
   /** @pdOid 8a2c53c2-1054-4181-93ed-42349de4cf0a */
   private static final String LAN_EDT = "/configManagement/monitoringPoint/monitoringLaneEdit";
   /** @pdOid 7d298a50-1a5f-4ed0-a195-609fdf000a4b */
   private static final String LAN_VIW = "/configManagement/monitoringPoint/monitoringLaneView";
   /** @pdOid 60125538-641c-4c4a-8387-b476c4f0a680 */
   @Autowired
   private CertificationService certificationService;
   /** @pdOid b3764bfa-dc11-415b-bafe-3d4a3dd9b8c5 */
   @Autowired
   private LaneService laneService;
   /** @pdOid 42beb007-16d9-4b0e-be91-b330cad23032 */
   @Autowired
   private SPIRoadSectionService spiRoadSectionService;
   /** @pdOid 58954124-73a0-4b25-b67d-98c6833639f8 */
   @Autowired
   private SPIMonitoringPointService spiMonitoringPointService;
   
   /** @param request
    * @exception Exception
    * @pdOid 6b0a086e-0cf3-48f6-8e0b-31fca6d42910 */
   @RequestMapping(value = "/showMonitoringPointSearch.do")
   public ModelAndView handleShowMonitoringPointSearch(HttpServletRequest request) throws Exception {
   	try {
   		Map<String, Object> model = new HashMap<>();
   		// 路段信息
   		List<Section> lstSection = spiRoadSectionService.findByQuery(new Section());
   		model.put("lstSection", lstSection);
   		return new ModelAndView(MP_SCH, model);
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   	return null;
   }
   
   /** @param request 
    * @param monitoringPoint 
    * @param pagination
    * @pdOid c2c3c677-de69-4648-bc3a-6caa14cf0fff */
   @RequestMapping(value = "/ajaxMonitoringPointSearchList.do", method = RequestMethod.POST)
   public ModelAndView handleAjaxFindMonitoringPointSearchList(HttpServletRequest request, MonitoringPoint monitoringPoint, Pagination pagination) {
   try {
   	Map<String, Object> model = new HashMap<>();
   	Page<MonitoringPoint> page = spiMonitoringPointService.findPage(monitoringPoint, pagination);
   	model.put("page", page);
   	return new ModelAndView(MP_SCH_LST, model);
   } catch (Exception e) {
   	e.printStackTrace();
   }
   return null;
    }
   
   /** @param request 
    * @param monitoringPointId 
    * @param isVisible
    * @pdOid b8d63577-84f1-4438-a392-cabf7bd28d05 */
   @RequestMapping(value = "/ajaxFindMonitoringLaneList.do", method = RequestMethod.POST)
   public ModelAndView handleAjaxFindMonitoringLaneList(HttpServletRequest request, String monitoringPointId, String isVisible) {
   	try {
   		Map<String, Object> model = new HashMap<>();
   		if (!StringUtils.isEmpty(monitoringPointId)) {
   			// 通过lane查找车道信息
   			List<Lane> lstLane = spiMonitoringPointService.findMonitoringLaneByMonitoringPointId(monitoringPointId);
   			model.put("lstLane", lstLane);
   		}
   		//按钮是否可见
   		model.put("isVisible", isVisible);
   		//用于新增时判断是否显示监测车道list中的新增按钮
   		model.put("monitoringPointId", monitoringPointId);
   		return new ModelAndView(LAN_LST, model);
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   	return null;
   }
   
   /** @param request 
    * @param monitoringPointId
    * @exception Exception
    * @pdOid c2feb416-2d32-405c-96b0-c0cee64956c3 */
   @RequestMapping(value = "/ajaxShowMonitoringPointEdit.do", method = RequestMethod.POST)
   public ModelAndView handleAjaxShowMonitoringPointEdit(HttpServletRequest request, String monitoringPointId) throws Exception {
   try {
   	Map<String, Object> model = new HashMap<>();
   	// 路段信息
   	List<Section> lstSection = spiRoadSectionService.findByQuery(new Section());
   	model.put("lstSection", lstSection);
   	// 行驶方向
   	List<SysCode> lstTravelDirection = spiSysCodeService.getSysCodeListByTypeCode(SysCodeType.TRAVEL_DIRECTION);
   	model.put("lstTravelDirection", lstTravelDirection);
   
   	if (!StringUtils.isEmpty(monitoringPointId)) {
   		MonitoringPoint monitoringPoint=spiMonitoringPointService.findMonitoringPointById(monitoringPointId);
   		model.put("monitoringPoint",monitoringPoint);
   	}
   	return new ModelAndView(MP_EDT, model);
   } catch (Exception e) {
   	e.printStackTrace();
   }
   return null;
     }
   
   /** @param request 
    * @param response 
    * @param monitoringPoint
    * @exception Exception
    * @pdOid 48ca3e23-8567-43c4-9103-416acd674377 */
   @RequestMapping(value = "/ajaxSaveMonitoringPoint.do", method = RequestMethod.POST)
   public void handleAjaxSaveMonitoringPoint(HttpServletRequest request, HttpServletResponse response, MonitoringPoint monitoringPoint) throws Exception {
   try {
   		spiMonitoringPointService.saveMonitoryPoint(monitoringPoint);
   } catch (Exception e) {
   	e.printStackTrace();
   }
    }
   
   /** @param request 
    * @param monitoringPointId
    * @exception Exception
    * @pdOid 95c9252f-2f70-4408-b9a5-5235beb51c6c */
   @RequestMapping(value = "/ajaxShowMonitoringPointView.do", method = RequestMethod.POST)
   public ModelAndView handleAjaxShowMonitoringPointView(HttpServletRequest request, String monitoringPointId) throws Exception {
   	try {
   		Map<String, Object> model = new HashMap<>();
   		if (!StringUtils.isEmpty(monitoringPointId)) {
   			MonitoringPoint monitoringPoint=spiMonitoringPointService.findMonitoringPointById(monitoringPointId);
   			model.put("monitoringPoint",monitoringPoint);
   		}
   		return new ModelAndView(MP_VIW, model);
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   	return null;
   }
   
   /** @param request 
    * @param response 
    * @param monitoringPointIds
    * @exception Exception
    * @pdOid ca9144b1-a9f2-485d-b8fc-57a59ca439bd */
   @RequestMapping(value = "/ajaxDeleteMonitoringPointByIds.do", method = RequestMethod.POST)
   public void handleAjaxDeleteMonitoringPointByIds(HttpServletRequest request, HttpServletResponse response, String monitoringPointIds) throws Exception {
   try {
   	spiMonitoringPointService.deleteMonitoringPointByIds(monitoringPointIds);
   } catch (Exception e) {
   	e.printStackTrace();
   }
    }
   
   /** @param request 
    * @param monitoringLaneId 
    * @param monitoringPointId
    * @exception Exception
    * @pdOid c4e4e98b-9ed1-47fa-94b5-639a5a99365f */
   @RequestMapping(value = "/ajaxShowMonitoringLaneEdit.do", method = RequestMethod.POST)
   public ModelAndView handleAjaxShowMonitoringLaneEdit(HttpServletRequest request, String monitoringLaneId, String monitoringPointId) throws Exception {
   try {
   	Map<String, Object> model = new HashMap<>();
   	List<Certification> lstCertification = certificationService.getCertificationByCondition(new Certification());
   	model.put("lstCertification", lstCertification);
   	Lane monitoringLane=new Lane();
   	if (!StringUtils.isEmpty(monitoringLaneId)) {
   		monitoringLane=spiMonitoringPointService.findMonitoringLaneById(monitoringLaneId);
   	}
   	monitoringLane.setMonitorid(Long.valueOf(monitoringPointId));
   	model.put("monitoringLane", monitoringLane);
   	model.put("listLaneConfig", monitoringLane.getLaneConfigList());
   	model.put("listVehicleTravelStrategy", monitoringLane.getDrivingstrategyList());
   	model.put("certification", monitoringLane.getCertification());
   	return new ModelAndView(LAN_EDT, model);
   } catch (Exception e) {
   	e.printStackTrace();
   }
   return null;
    }
   
   /** @param request 
    * @param monitoringLaneId
    * @exception Exception
    * @pdOid 62d82845-f368-466a-aa53-5aff856dfcd7 */
   @RequestMapping(value = "/ajaxShowMonitoringLaneView.do", method = RequestMethod.POST)
   public ModelAndView handleAjaxShowMonitoringLaneView(HttpServletRequest request, String monitoringLaneId) throws Exception {
   try {
   	Map<String, Object> model = new HashMap<>();
   	List<Certification> lstCertification = certificationService.getCertificationByCondition(new Certification());
   	model.put("lstCertification", lstCertification);
   	if (!StringUtils.isEmpty(monitoringLaneId)) {
   		Lane monitoringLane=spiMonitoringPointService.findMonitoringLaneById(monitoringLaneId);
   		model.put("monitoringLane", monitoringLane);
   		model.put("listLaneConfig", monitoringLane.getLaneConfigList());
   		model.put("listVehicleTravelStrategy", monitoringLane.getDrivingstrategyList());
   		model.put("certification", monitoringLane.getCertification());
   	}
   	return new ModelAndView(LAN_VIW, model);
   } catch (Exception e) {
   	e.printStackTrace();
   }
   return null;
    }
   
   /** @param request 
    * @param response 
    * @param monitoringLaneId
    * @exception Exception
    * @pdOid fd10a162-38e1-471e-add5-f79b66adb5d9 */
   @RequestMapping(value = "/ajaxDeleteMonitoringLaneById.do", method = RequestMethod.POST)
   public void handleAjaxDeleteMonitoringLaneById(HttpServletRequest request, HttpServletResponse response, String monitoringLaneId) throws Exception {
   	try {
   		spiMonitoringPointService.deleteMonitoringPointLaneById(monitoringLaneId);
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   }
   
   /** @param request 
    * @param response 
    * @param lane
    * @exception Exception
    * @pdOid 580d48dd-d215-42ff-b87e-901fec70ede0 */
   @RequestMapping(value = "/ajaxSaveMonitoringLane.do", method = RequestMethod.POST)
   public void handleAjaxSaveMonitoringLane(HttpServletRequest request, HttpServletResponse response, Lane lane) throws Exception {
   try {
   		spiMonitoringPointService.saveMonitoringLane(lane);
   } catch (Exception e) {
   	e.printStackTrace();
   }
    }

}